package com.wlhse.util;

import com.wlhse.dao.CheckRecordDao;
import com.wlhse.dao.ModuleDao;
import com.wlhse.dto.CheckRecordRectRecordDto;
import com.wlhse.dto.TreeDto;
import com.wlhse.dto.outDto.*;
import com.wlhse.entity.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;


@Component
//适配器
public class TreeUtil {

    @Resource
    private ModuleDao moduleDao;

    @Resource
    private CheckRecordDao checkRecordDao;

    public List<TreeDto> GetModuleTree(List<ModulePojo> pojos) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (ModulePojo pojo : pojos) {
            TreeDto treeDto = new TreeDto();
            treeDto.setLabel(pojo.getName());
            treeDto.setNodeCode(pojo.getModuleCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getModuleCode().length()) == -1)
                code.add(pojo.getModuleCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> GetCheckList_Item(List<CheckListOutDto2> pojos) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (CheckListOutDto2 pojo : pojos) {
            TreeDto treeDto = new TreeDto();
            treeDto.setLabel(pojo.getName());
            treeDto.setNodeCode(pojo.getCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getCode().length()) == -1)
                code.add(pojo.getCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> GetRoleModuleTree(List<RoleModulePojo> pojos) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (RoleModulePojo pojo : pojos) {
            TreeDto treeDto = new TreeDto();
            ModulePojo modulePojo = moduleDao.queryByModuleCode(pojo.getModuleCode());
            treeDto.setLabel(modulePojo.getName());
            treeDto.setNodeCode(pojo.getModuleCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getModuleCode().length()) == -1)
                code.add(pojo.getModuleCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> getDataDictTree(List<DataDictPojo> dataDictPojos) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (DataDictPojo pojo : dataDictPojos) {
            TreeDto treeDto = new TreeDto();
            treeDto.setLabel(pojo.getName());
            treeDto.setNodeCode(pojo.getDictCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getDictCode().length()) == -1)
                code.add(pojo.getDictCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> generalGetChechItemTree(List<CheckItemPojo> list) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (CheckItemPojo pojo : list) {
            if (pojo.getStatus().equals("staus"))
                continue;
            TreeDto treeDto = new TreeDto();
            treeDto.setId(pojo.getCheckItemCode());
            treeDto.setLabel(pojo.getCheckItemName());
            treeDto.setNodeCode(pojo.getCheckItemCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getCheckItemCode().length()) == -1)
                code.add(pojo.getCheckItemCode().length());
        }
        return returnList(map1, code);
    }

    private static final String staus = "停用";

    public List<TreeDto> getLeaderChechItemTree(List<LeaderCheckItemPojo> list) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (LeaderCheckItemPojo pojo : list) {
            if (pojo.getStatus().equals("staus"))
                continue;
            TreeDto treeDto = new TreeDto();
            treeDto.setId(pojo.getCheckItemCode());
            treeDto.setLabel(pojo.getCheckItemName());
            treeDto.setNodeCode(pojo.getCheckItemCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getCheckItemCode().length()) == -1)
                code.add(pojo.getCheckItemCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> getChechItemTreeV2(List<CheckItemPojo> list1, List<LeaderCheckItemPojo> list2) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (CheckItemPojo pojo : list1) {
            if (pojo.getStatus().equals("staus"))
                continue;
            TreeDto treeDto = new TreeDto();
            treeDto.setId(pojo.getCheckItemCode());
            treeDto.setLabel(pojo.getCheckItemName());
            treeDto.setNodeCode(pojo.getCheckItemCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getCheckItemCode().length()) == -1)
                code.add(pojo.getCheckItemCode().length());
        }
        for (LeaderCheckItemPojo pojo : list2) {
            if (pojo.getStatus().equals("staus"))
                continue;
            TreeDto treeDto = new TreeDto();
            treeDto.setId(pojo.getCheckItemCode());
            treeDto.setLabel(pojo.getCheckItemName());
            treeDto.setNodeCode(pojo.getCheckItemCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getCheckItemCode().length()) == -1)
                code.add(pojo.getCheckItemCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> getCompanyTree(List<CompanyPojo> companyPojo) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (CompanyPojo pojo : companyPojo) {
            TreeDto treeDto = new TreeDto();
            treeDto.setId(pojo.getCompanyCode());
            treeDto.setLabel(pojo.getName());
            treeDto.setNodeCode(pojo.getCompanyCode());
            treeDto.setOrder(pojo.getOrder());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getCompanyCode().length()) == -1)
                code.add(pojo.getCompanyCode().length());
        }
        return returnOrderList(map1, code);
    }

    public List<TreeDto> getTaskAndProcessTree(List<TaskAndProcessPojo> taskAndProcessPojos) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (TaskAndProcessPojo pojo : taskAndProcessPojos) {
            TreeDto treeDto = new TreeDto();
            treeDto.setId(pojo.getTaskAndProcessName());
            treeDto.setLabel(pojo.getTaskAndProcessName());
            treeDto.setNodeCode(pojo.getTaskAndProcessCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getTaskAndProcessCode().length()) == -1)
                code.add(pojo.getTaskAndProcessCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> getProblemFactorTree(List<ProblemFactorPojo> problemFactorPojos) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (ProblemFactorPojo pojo : problemFactorPojos) {
            TreeDto treeDto = new TreeDto();
            treeDto.setLabel(pojo.getProblemFactorName());
            treeDto.setNodeCode(pojo.getProblemFactorCode());
            map1.put(pojo.getProblemFactorCode(), treeDto);

            if (code.indexOf(pojo.getProblemFactorCode().length()) == -1)
                code.add(pojo.getProblemFactorCode().length());
        }
        return returnList(map1, code);
    }

    public List<TreeDto> getRoleModuleOutDto(List<RoleModuleOutDto> roleModuleOutDtos) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (RoleModuleOutDto pojo : roleModuleOutDtos) {
            TreeDto treeDto = new TreeDto();
            treeDto.setLabel(pojo.getLabel());
            treeDto.setNodeCode(pojo.getModuleCode());
            treeDto.setuRl(pojo.getuRL());
            treeDto.setImg(pojo.getImg());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getModuleCode().length()) == -1)
                code.add(pojo.getModuleCode().length());
        }
        return returnList(map1, code);
    }

    //返回树状，并对节点但order进行同层类的排序
    public List<TreeDto> returnOrderList(Map<String, TreeDto> map, List<Integer> code) {
        List<TreeDto> result = new ArrayList<>();
        Collections.sort(code);
        for (Map.Entry<String, TreeDto> entry : map.entrySet()) {
            String key = entry.getKey();
            if (key.length() == code.get(0))//根节点
                result.add(entry.getValue());
            else {
                TreeDto treeDto = map.get(key.substring(0, code.get(code.indexOf(key.length()) - 1)));//父节点
                if (null == treeDto)
                    continue;
                if (null == treeDto.getChildren()) {
                    List<TreeDto> tmp = new LinkedList<>();
                    tmp.add(entry.getValue());
                    treeDto.setChildren(tmp);
                } else{//按order升序 插入排序
                    List<TreeDto> children = treeDto.getChildren();
                    TreeDto node = entry.getValue();
                    boolean flag=true;
                    for (TreeDto child : children) {//按order插入排序
                        int index = children.indexOf(child);
                        if (child.getOrder()>node.getOrder()){
                            children.add(index,node);
                            flag=false;
                            break;
                        }
                    }
                    if(flag) children.add(node);
                }

            }
        }
        return result;
    }

    public List<TreeDto> returnList(Map<String, TreeDto> map, List<Integer> code) {
        List<TreeDto> result = new ArrayList<>();
        Collections.sort(code);
        for (Map.Entry<String, TreeDto> entry : map.entrySet()) {
            String key = entry.getKey();
            if (key.length() == code.get(0))//根节点
                result.add(entry.getValue());
            else {
                TreeDto treeDto = map.get(key.substring(0, code.get(code.indexOf(key.length()) - 1)));//父节点
                if (null == treeDto)
                    continue;
                if (null == treeDto.getChildren()) {
                    List<TreeDto> tmp = new ArrayList<>();
                    tmp.add(entry.getValue());
                    treeDto.setChildren(tmp);
                } else
                    treeDto.getChildren().add(entry.getValue());
            }
        }
        return result;
    }

    public List<MenuOutDto> returnMenuOutDtoList(Map<String, MenuOutDto> map1, int parentLength) {
        List<MenuOutDto> list = new ArrayList<>();
        Map<String, MenuOutDto> treeMap = new TreeMap<String, MenuOutDto>(map1);
        for (Map.Entry<String, MenuOutDto> entry : treeMap.entrySet()) {
            if (entry.getKey().length() == parentLength) {
                list.add(entry.getValue());
            }
        }
        for (Map.Entry<String, MenuOutDto> entry : treeMap.entrySet()) {
            String code = entry.getKey();
            if (code.length() ==6) {
                code = code.substring(0, parentLength);
                MenuOutDto parentTree = map1.get(code);//获取父级节点
                if (parentTree != null) {
                    if (parentTree.getChildren() != null) {
                        parentTree.getChildren().add(entry.getValue());
                    } else {
                        List<MenuOutDto> list1 = new ArrayList<>();
                        list1.add(entry.getValue());
                        parentTree.setChildren(list1);
                    }

                }
            }
        }
        for (Map.Entry<String, MenuOutDto> entry : treeMap.entrySet()) {
            String code = entry.getKey();
            if (code.length() ==8) {
                code = code.substring(0, 6);
                MenuOutDto parentTree = map1.get(code);//获取父级节点
                if (parentTree != null) {
                    if (parentTree.getChildren() != null) {
                        parentTree.getChildren().add(entry.getValue());
                    } else {
                        List<MenuOutDto> list1 = new ArrayList<>();
                        list1.add(entry.getValue());
                        parentTree.setChildren(list1);
                    }

                }
            }
        }
        return list;
    }

    public List<TreeDto> getChangQinCompanyTree(List<CompanyPojo> companyPojo) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (CompanyPojo pojo : companyPojo) {
            TreeDto treeDto = new TreeDto();
            treeDto.setId(pojo.getCompanyCode());
            treeDto.setLabel(pojo.getName());
            treeDto.setNodeCode(pojo.getCompanyCode());
            map1.put(treeDto.getNodeCode(), treeDto);

            if (code.indexOf(pojo.getCompanyCode().length()) == -1)
                code.add(pojo.getCompanyCode().length());
        }
        return returnList(map1, code);
    }

    public List<SuperVisionScopeOutDto> getManageTaskOutTree(String areaName, List<SuperVisionScopeOutDto> list_treeIn){
        List<SuperVisionScopeOutDto> list = new ArrayList<>();
        for(SuperVisionScopeOutDto pojo:list_treeIn){

        }
        return list;
    }

    //checkRecordRectRecordTree相关
    public List<CheckRecordRectRecordDto> returnCheckRectRecord(HashMap<CheckRecordRectRecordDto, List<RectRecordOutDto>> map, List<Integer> code) {
        List<CheckRecordRectRecordDto> result = new ArrayList<>();
        Collections.sort(code);
        for (Map.Entry<CheckRecordRectRecordDto, List<RectRecordOutDto>> entry : map.entrySet()) {
            CheckRecordRectRecordDto checkRecordRectRecordDto = entry.getKey();
            checkRecordRectRecordDto.setChildren(map.get(checkRecordRectRecordDto));
            result.add(checkRecordRectRecordDto);
        }
        //按checkDate降序排序
        Collections.sort(result, new Comparator<CheckRecordRectRecordDto>() {
            @Override
            public int compare(CheckRecordRectRecordDto record1, CheckRecordRectRecordDto record2) {
                String checkDate1=record1.getCheckDate();
                String checkDate2=record2.getCheckDate();
                long longDate1 = Long.valueOf(checkDate1.replaceAll("[-\\s:]",""));
                long longDate2 = Long.valueOf(checkDate2.replaceAll("[-\\s:]",""));
                if(longDate1>=longDate2){
                    return -1;
                }else{
                    return 1;
                }
            }
        });
        return result;
    }

    public List<CheckRecordRectRecordDto> getCheckRecordRectTree(List<CheckRecordRectRecord> checkRecordRectRecords) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        HashMap<CheckRecordRectRecordDto, List<RectRecordOutDto>> map=new LinkedHashMap<>();
//        HashMap<CheckRecordRectRecordDto, List<RectRecordOutDto>> map= new HashMap<>();
        List<Integer> code = new ArrayList<>();
        for (CheckRecordRectRecord pojo : checkRecordRectRecords) {
            if (code.indexOf(pojo.getCheckRecordID()) == -1){
                code.add(pojo.getCheckRecordID());
                CheckRecordRectRecordDto checkRecordPojo = new CheckRecordRectRecordDto();
                RectRecordOutDto rectRecordOutDto =  new RectRecordOutDto();
                List<RectRecordOutDto> list = new ArrayList<>();
                checkRecordPojo.setId(pojo.getCheckRecordID());
                checkRecordPojo.setCheckStaffID(pojo.getCheckStaffID());
                if (pojo.getCheckStaffName()!=null)
                    checkRecordPojo.setCheckPerson(pojo.getCheckStaffName());
                if (pojo.getCheckType()!=null)
                    checkRecordPojo.setCheckType(pojo.getCheckType());
                if (pojo.getCheckLevel()!=null)
                    checkRecordPojo.setCheckLevel(pojo.getCheckLevel());
                if (pojo.getCheckDate()!=null)
                    checkRecordPojo.setCheckDate(pojo.getCheckDate());
                checkRecordPojo.setCompanyName(pojo.getCompanyName());
                checkRecordPojo.setCompanyCode(pojo.getCompanyCode());
                checkRecordPojo.setParentCompanyName(pojo.getParentCompanyName());
                checkRecordPojo.setCheckStation(pojo.getAddress());
                checkRecordPojo.setCheckItem(pojo.getCheckItem());
                checkRecordPojo.setCheckListItemCode(pojo.getCheckListItemCode());
                checkRecordPojo.setCheckListItemName(pojo.getCheckListItemName());
                checkRecordPojo.setDescription(pojo.getProblemDescription());
                checkRecordPojo.setProblemType(pojo.getProblemType());
                checkRecordPojo.setProblemRank(pojo.getProblemRank());
                checkRecordPojo.setProblemSource(pojo.getProblemSource());
                checkRecordPojo.setProblemGist(pojo.getProblemGist());
                checkRecordPojo.setHseFactor(pojo.getHseFactor());
                checkRecordPojo.setResponsePersonID(pojo.getResponsePersonID());
                checkRecordPojo.setResponsePersonName(pojo.getResponsePersonName());
                checkRecordPojo.setEmploymentProperty(pojo.getEmploymentProperty());
                checkRecordPojo.setWorkingAge(pojo.getWorkingAge());
                checkRecordPojo.setWorkingName(pojo.getWorkingName());
                checkRecordPojo.setSupervisorID(pojo.getSupervisorID());
                checkRecordPojo.setSupervisorName(pojo.getSupervisorName());
                checkRecordPojo.setCheckAttach1(pojo.getCheckAttach1());
                checkRecordPojo.setCheckAttach2(pojo.getCheckAttach2());
                checkRecordPojo.setCheckAttach3(pojo.getCheckAttach3());
                checkRecordPojo.setCheckAttach4(pojo.getCheckAttach4());
                checkRecordPojo.setCheckVideo(pojo.getCheckVideo());
                checkRecordPojo.setImmediately(pojo.getImmediately());
                checkRecordPojo.setLostScore(pojo.getLostScore());
                checkRecordPojo.setPenalty(pojo.getPenalty());
                checkRecordPojo.setEducation(pojo.getEducation());
                checkRecordPojo.setRectification(pojo.getRectification());
                checkRecordPojo.setRectAttach1(pojo.getRectAttach1());
                checkRecordPojo.setRectAttach2(pojo.getRectAttach2());
                checkRecordPojo.setRectAttach3(pojo.getRectAttach3());
                checkRecordPojo.setRectAttach4(pojo.getRectAttach4());
                checkRecordPojo.setRectVideo(pojo.getRectVideo());
                if (pojo.getVerifyPersonEmpID()!=null)
                    checkRecordPojo.setVerifyPersonEmpID(pojo.getVerifyPersonEmpID());
                checkRecordPojo.setVerifyPersonName(pojo.getVerifyPersonName());
                checkRecordPojo.setVerifyDate(pojo.getVerifyDate());
                checkRecordPojo.setRectEffect(pojo.getRectEffect());
                checkRecordPojo.setStatus(pojo.getStatus());
                checkRecordPojo.setSupervisionTaskCode(pojo.getSupervisionTaskCode());
                checkRecordPojo.setSupervisionTaskDetail2ID(pojo.getSupervisionTaskDetail2ID());
                checkRecordPojo.setRound(pojo.getRound());
                checkRecordPojo.setCheckListID(pojo.getCheckListID());
                checkRecordPojo.setCheckListName(pojo.getCheckListName());
                checkRecordPojo.setCheckRecordNo(pojo.getCheckRecordNo());
                checkRecordPojo.setBasicCompanyName(pojo.getBasicCompanyName());
                checkRecordPojo.setNote(pojo.getNote());
                //hashmap的值
                rectRecordOutDto.setRectRecordID(pojo.getRectRecordID());
                rectRecordOutDto.setSupervisorID(pojo.getRectSupervisorID());
                rectRecordOutDto.setSupervisorName(pojo.getRectSupervisorName());
                rectRecordOutDto.setRectAttach1(pojo.getRectRecordAttach1());
                rectRecordOutDto.setRectAttach2(pojo.getRectRecordAttach2());
                rectRecordOutDto.setRectAttach3(pojo.getRectRecordAttach3());
                rectRecordOutDto.setRectAttach4(pojo.getRectRecordAttach4());
                rectRecordOutDto.setRectVideo(pojo.getRectRecordVideo());
                rectRecordOutDto.setRectDescription(pojo.getRectRecordDescription());
                rectRecordOutDto.setRectFile(pojo.getRectRecordFile());
                rectRecordOutDto.setRectDate(pojo.getRectDate());
                rectRecordOutDto.setRectEffect(pojo.getRectRecordEffect());
                list.add(rectRecordOutDto);
                map.put(checkRecordPojo,list);
            }else {
                RectRecordOutDto rectRecordOutDto =  new RectRecordOutDto();
                List<RectRecordOutDto> list=new ArrayList<>();
                for(Map.Entry<CheckRecordRectRecordDto, List<RectRecordOutDto>> entry : map.entrySet()){
                    CheckRecordRectRecordDto checkRecordRectRecordDto= entry.getKey();
                    if (checkRecordRectRecordDto.getId()==pojo.getCheckRecordID()){
                        list = map.get(checkRecordRectRecordDto);
                        break;
                    }
                }
                //hashmap的值
                rectRecordOutDto.setRectRecordID(pojo.getRectRecordID());
                rectRecordOutDto.setSupervisorID(pojo.getRectSupervisorID());
                rectRecordOutDto.setSupervisorName(pojo.getRectSupervisorName());
                rectRecordOutDto.setRectAttach1(pojo.getRectRecordAttach1());
                rectRecordOutDto.setRectAttach2(pojo.getRectRecordAttach2());
                rectRecordOutDto.setRectAttach3(pojo.getRectRecordAttach3());
                rectRecordOutDto.setRectAttach4(pojo.getRectRecordAttach4());
                rectRecordOutDto.setRectVideo(pojo.getRectRecordVideo());
                rectRecordOutDto.setRectDescription(pojo.getRectRecordDescription());
                rectRecordOutDto.setRectFile(pojo.getRectRecordFile());
                rectRecordOutDto.setRectDate(pojo.getRectDate());
                rectRecordOutDto.setRectEffect(pojo.getRectRecordEffect());
                list.add(rectRecordOutDto);
            }
        }
        return returnCheckRectRecord(map, code);
    }

    public List<CheckRecordRectRecordDto> getCheckRecordRectTree2(List<CheckRecordRectRecord> checkRecordRectRecords) {
       //做返回的树
        List<CheckRecordRectRecordDto> res = new LinkedList<>();
        for(CheckRecordRectRecord pojo :checkRecordRectRecords){
            CheckRecordRectRecordDto dto = new CheckRecordRectRecordDto();
            dto.setId(pojo.getCheckRecordID());
            dto.setCheckStaffID(pojo.getCheckStaffID());
            dto.setCheckPerson(pojo.getCheckStaffName());
            dto.setCheckType(pojo.getCheckType());
            dto.setCheckLevel(pojo.getCheckLevel());
            dto.setCheckDate(pojo.getCheckDate());
            dto.setCompanyName(pojo.getCompanyName());
            dto.setCompanyCode(pojo.getCompanyCode());
            dto.setParentCompanyName(pojo.getParentCompanyName());
            dto.setCheckStation(pojo.getAddress());
            dto.setCheckItem(pojo.getCheckItem());
            dto.setCheckListItemCode(pojo.getCheckListItemCode());
            dto.setCheckListItemName(pojo.getCheckListItemName());
            dto.setDescription(pojo.getProblemDescription());
            dto.setProblemType(pojo.getProblemType());
            dto.setProblemRank(pojo.getProblemRank());
            dto.setProblemSource(pojo.getProblemSource());
            dto.setProblemGist(pojo.getProblemGist());
            dto.setHseFactor(pojo.getHseFactor());
            dto.setResponsePersonID(pojo.getResponsePersonID());
            dto.setResponsePersonName(pojo.getResponsePersonName());
            dto.setEmploymentProperty(pojo.getEmploymentProperty());
            dto.setWorkingAge(pojo.getWorkingAge());
            dto.setWorkingName(pojo.getWorkingName());
            dto.setSupervisorID(pojo.getSupervisorID());
            dto.setSupervisorName(pojo.getSupervisorName());
            dto.setCheckAttach1(pojo.getCheckAttach1());
            dto.setCheckAttach2(pojo.getCheckAttach2());
            dto.setCheckAttach3(pojo.getCheckAttach3());
            dto.setCheckAttach4(pojo.getCheckAttach4());
            dto.setCheckVideo(pojo.getCheckVideo());
            dto.setImmediately(pojo.getImmediately());
            dto.setLostScore(pojo.getLostScore());
            dto.setPenalty(pojo.getPenalty());
            dto.setEducation(pojo.getEducation());
            dto.setRectification(pojo.getRectification());
            dto.setRectAttach1(pojo.getRectAttach1());
            dto.setRectAttach2(pojo.getRectAttach2());
            dto.setRectAttach3(pojo.getRectAttach3());
            dto.setRectAttach4(pojo.getRectAttach4());
            dto.setRectVideo(pojo.getRectVideo());
            dto.setVerifyPersonEmpID(pojo.getVerifyPersonEmpID());
            dto.setVerifyPersonName(pojo.getVerifyPersonName());
            dto.setVerifyDate(pojo.getVerifyDate());
            dto.setRectEffect(pojo.getRectEffect());
            dto.setStatus(pojo.getStatus());
            dto.setSupervisionTaskCode(pojo.getSupervisionTaskCode());
            dto.setSupervisionTaskDetail2ID(pojo.getSupervisionTaskDetail2ID());
            dto.setRound(pojo.getRound());
            dto.setCheckListID(pojo.getCheckListID());
            dto.setCheckListName(pojo.getCheckListName());
            dto.setCheckRecordNo(pojo.getCheckRecordNo());
            dto.setBasicCompanyName(pojo.getBasicCompanyName());
            dto.setNote(pojo.getNote());

            //查找子节点
            List<RectRecordOutDto> rectRecords = checkRecordDao.queryRectRecord(pojo.getCheckRecordID());
            if(rectRecords.size()>0){
                dto.setChildren(rectRecords);
            }else {
                List<RectRecordOutDto> recordOutDtos=new LinkedList<>();
                RectRecordOutDto r1=new RectRecordOutDto();
                r1.setRectAttach1("");
                r1.setRectAttach2("");
                r1.setRectAttach3("");
                r1.setRectAttach4("");
                r1.setRectDate("");
                r1.setRectDescription("");
                r1.setRectEffect("");
                r1.setRectFile("");
                r1.setRectVideo("");
                r1.setSupervisorName("");
                recordOutDtos.add(r1);
                dto.setChildren(recordOutDtos);
            }
            res.add(dto);

        }
        return res;
    }

    public List<CheckRecordRectRecordDto> getCheckRecordRectMyTree(List<CheckRecordRectRecord> checkRecordRectRecords) {
        Map<String, TreeDto> map1 = new TreeMap<>();
//        HashMap<CheckRecordRectRecordDto, List<RectRecordOutDto>> map= new HashMap<>();
        HashMap<CheckRecordRectRecordDto, List<RectRecordOutDto>> map= new LinkedHashMap<>();
        List<Integer> code = new ArrayList<>();
        for (CheckRecordRectRecord pojo : checkRecordRectRecords) {
            if (code.indexOf(pojo.getCheckRecordID()) == -1){
                code.add(pojo.getCheckRecordID());
                CheckRecordRectRecordDto checkRecordPojo = new CheckRecordRectRecordDto();
                RectRecordOutDto rectRecordOutDto =  new RectRecordOutDto();
                List<RectRecordOutDto> list = new ArrayList<>();
                checkRecordPojo.setId(pojo.getCheckRecordID());
                checkRecordPojo.setCheckStaffID(pojo.getCheckStaffID());
                if (pojo.getCheckStaffName()!=null)
                    checkRecordPojo.setCheckPerson(pojo.getCheckStaffName());
                if (pojo.getCheckType()!=null)
                    checkRecordPojo.setCheckType(pojo.getCheckType());
                if (pojo.getCheckLevel()!=null)
                    checkRecordPojo.setCheckLevel(pojo.getCheckLevel());
                if (pojo.getCheckDate()!=null)
                    checkRecordPojo.setCheckDate(pojo.getCheckDate());
                checkRecordPojo.setCompanyName(pojo.getCompanyName());
                checkRecordPojo.setCompanyCode(pojo.getCompanyCode());
                checkRecordPojo.setParentCompanyName(pojo.getParentCompanyName());
                checkRecordPojo.setCheckStation(pojo.getAddress());
                checkRecordPojo.setCheckItem(pojo.getCheckItem());
                checkRecordPojo.setCheckListItemCode(pojo.getCheckListItemCode());
                checkRecordPojo.setCheckListItemName(pojo.getCheckListItemName());
                checkRecordPojo.setDescription(pojo.getProblemDescription());
                checkRecordPojo.setProblemType(pojo.getProblemType());
                checkRecordPojo.setProblemRank(pojo.getProblemRank());
                checkRecordPojo.setProblemSource(pojo.getProblemSource());
                checkRecordPojo.setProblemGist(pojo.getProblemGist());
                checkRecordPojo.setHseFactor(pojo.getHseFactor());
                checkRecordPojo.setResponsePersonID(pojo.getResponsePersonID());
                checkRecordPojo.setResponsePersonName(pojo.getResponsePersonName());
                checkRecordPojo.setEmploymentProperty(pojo.getEmploymentProperty());
                checkRecordPojo.setWorkingAge(pojo.getWorkingAge());
                checkRecordPojo.setWorkingName(pojo.getWorkingName());
                checkRecordPojo.setSupervisorID(pojo.getSupervisorID());
                checkRecordPojo.setSupervisorName(pojo.getSupervisorName());
                checkRecordPojo.setCheckAttach1(pojo.getCheckAttach1());
                checkRecordPojo.setCheckAttach2(pojo.getCheckAttach2());
                checkRecordPojo.setCheckAttach3(pojo.getCheckAttach3());
                checkRecordPojo.setCheckAttach4(pojo.getCheckAttach4());
                checkRecordPojo.setCheckVideo(pojo.getCheckVideo());
                checkRecordPojo.setImmediately(pojo.getImmediately());
                checkRecordPojo.setLostScore(pojo.getLostScore());
                checkRecordPojo.setPenalty(pojo.getPenalty());
                checkRecordPojo.setEducation(pojo.getEducation());
                checkRecordPojo.setRectification(pojo.getRectification());
                checkRecordPojo.setRectAttach1(pojo.getRectAttach1());
                checkRecordPojo.setRectAttach2(pojo.getRectAttach2());
                checkRecordPojo.setRectAttach3(pojo.getRectAttach3());
                checkRecordPojo.setRectAttach4(pojo.getRectAttach4());
                checkRecordPojo.setRectVideo(pojo.getRectVideo());
                if (pojo.getVerifyPersonEmpID()!=null)
                    checkRecordPojo.setVerifyPersonEmpID(pojo.getVerifyPersonEmpID());
                checkRecordPojo.setVerifyPersonName(pojo.getVerifyPersonName());
                checkRecordPojo.setVerifyDate(pojo.getVerifyDate());
                checkRecordPojo.setRectEffect(pojo.getRectEffect());
                checkRecordPojo.setStatus(pojo.getStatus());
                checkRecordPojo.setSupervisionTaskCode(pojo.getSupervisionTaskCode());
                checkRecordPojo.setSupervisionTaskDetail2ID(pojo.getSupervisionTaskDetail2ID());
                checkRecordPojo.setRound(pojo.getRound());
                checkRecordPojo.setCheckListID(pojo.getCheckListID());
                checkRecordPojo.setCheckListName(pojo.getCheckListName());
                checkRecordPojo.setCheckRecordNo(pojo.getCheckRecordNo());
                checkRecordPojo.setBasicCompanyName(pojo.getBasicCompanyName());
                checkRecordPojo.setNote(pojo.getNote());
                //hashmap的值
                rectRecordOutDto.setRectRecordID(pojo.getRectRecordID());
                rectRecordOutDto.setSupervisorID(pojo.getRectSupervisorID());
                rectRecordOutDto.setSupervisorName(pojo.getRectSupervisorName());
                rectRecordOutDto.setRectAttach1(pojo.getRectRecordAttach1());
                rectRecordOutDto.setRectAttach2(pojo.getRectRecordAttach2());
                rectRecordOutDto.setRectAttach3(pojo.getRectRecordAttach3());
                rectRecordOutDto.setRectAttach4(pojo.getRectRecordAttach4());
                rectRecordOutDto.setRectVideo(pojo.getRectRecordVideo());
                rectRecordOutDto.setRectDescription(pojo.getRectRecordDescription());
                rectRecordOutDto.setRectFile(pojo.getRectRecordFile());
                rectRecordOutDto.setRectDate(pojo.getRectDate());
                rectRecordOutDto.setRectEffect(pojo.getRectRecordEffect());
                list.add(rectRecordOutDto);
                map.put(checkRecordPojo,list);
                System.out.println("111");
            }else {
                RectRecordOutDto rectRecordOutDto =  new RectRecordOutDto();
                List<RectRecordOutDto> list=new ArrayList<>();
                for(Map.Entry<CheckRecordRectRecordDto, List<RectRecordOutDto>> entry : map.entrySet()){
                    CheckRecordRectRecordDto checkRecordRectRecordDto= entry.getKey();
                    if (checkRecordRectRecordDto.getId()==pojo.getCheckRecordID()){
                        list = map.get(checkRecordRectRecordDto);
                        break;
                    }
                }
                //hashmap的值
                rectRecordOutDto.setRectRecordID(pojo.getRectRecordID());
                rectRecordOutDto.setSupervisorID(pojo.getRectSupervisorID());
                rectRecordOutDto.setSupervisorName(pojo.getRectSupervisorName());
                rectRecordOutDto.setRectAttach1(pojo.getRectRecordAttach1());
                rectRecordOutDto.setRectAttach2(pojo.getRectRecordAttach2());
                rectRecordOutDto.setRectAttach3(pojo.getRectRecordAttach3());
                rectRecordOutDto.setRectAttach4(pojo.getRectRecordAttach4());
                rectRecordOutDto.setRectVideo(pojo.getRectRecordVideo());
                rectRecordOutDto.setRectDescription(pojo.getRectRecordDescription());
                rectRecordOutDto.setRectFile(pojo.getRectRecordFile());
                rectRecordOutDto.setRectDate(pojo.getRectDate());
                rectRecordOutDto.setRectEffect(pojo.getRectRecordEffect());
                list.add(rectRecordOutDto);
                System.out.println("111");
            }
        }
        return returnCheckRectRecord(map, code);
    }

    public List<CheckRecordRectRecordDto> getCheckRecordMyVerifyTree(List<CheckRecordRectRecord> checkRecordRectRecords) {
        Map<String, TreeDto> map1 = new TreeMap<>();
        HashMap<CheckRecordRectRecordDto, List<RectRecordOutDto>> map= new HashMap<>();
        List<Integer> code = new ArrayList<>();
        for (CheckRecordRectRecord pojo : checkRecordRectRecords) {
            if (code.indexOf(pojo.getCheckRecordID()) == -1){
                code.add(pojo.getCheckRecordID());
                CheckRecordRectRecordDto checkRecordPojo = new CheckRecordRectRecordDto();
                RectRecordOutDto rectRecordOutDto =  new RectRecordOutDto();
                List<RectRecordOutDto> list = new ArrayList<>();
                checkRecordPojo.setId(pojo.getCheckRecordID());
                checkRecordPojo.setCheckStaffID(pojo.getCheckStaffID());
                if (pojo.getCheckStaffName()!=null)
                    checkRecordPojo.setCheckPerson(pojo.getCheckStaffName());
                if (pojo.getCheckType()!=null)
                    checkRecordPojo.setCheckType(pojo.getCheckType());
                if (pojo.getCheckLevel()!=null)
                    checkRecordPojo.setCheckLevel(pojo.getCheckLevel());
                if (pojo.getCheckDate()!=null)
                    checkRecordPojo.setCheckDate(pojo.getCheckDate());
                checkRecordPojo.setCompanyName(pojo.getCompanyName());
                checkRecordPojo.setCompanyCode(pojo.getCompanyCode());
                checkRecordPojo.setParentCompanyName(pojo.getParentCompanyName());
                checkRecordPojo.setCheckStation(pojo.getAddress());
                checkRecordPojo.setCheckItem(pojo.getCheckItem());
                checkRecordPojo.setCheckListItemCode(pojo.getCheckListItemCode());
                checkRecordPojo.setCheckListItemName(pojo.getCheckListItemName());
                checkRecordPojo.setDescription(pojo.getProblemDescription());
                checkRecordPojo.setProblemType(pojo.getProblemType());
                checkRecordPojo.setProblemRank(pojo.getProblemRank());
                checkRecordPojo.setProblemSource(pojo.getProblemSource());
                checkRecordPojo.setProblemGist(pojo.getProblemGist());
                checkRecordPojo.setHseFactor(pojo.getHseFactor());
                checkRecordPojo.setResponsePersonID(pojo.getResponsePersonID());
                checkRecordPojo.setResponsePersonName(pojo.getResponsePersonName());
                checkRecordPojo.setEmploymentProperty(pojo.getEmploymentProperty());
                checkRecordPojo.setWorkingAge(pojo.getWorkingAge());
                checkRecordPojo.setWorkingName(pojo.getWorkingName());
                checkRecordPojo.setSupervisorID(pojo.getSupervisorID());
                checkRecordPojo.setSupervisorName(pojo.getSupervisorName());
                checkRecordPojo.setCheckAttach1(pojo.getCheckAttach1());
                checkRecordPojo.setCheckAttach2(pojo.getCheckAttach2());
                checkRecordPojo.setCheckAttach3(pojo.getCheckAttach3());
                checkRecordPojo.setCheckAttach4(pojo.getCheckAttach4());
                checkRecordPojo.setCheckVideo(pojo.getCheckVideo());
                checkRecordPojo.setImmediately(pojo.getImmediately());
                checkRecordPojo.setLostScore(pojo.getLostScore());
                checkRecordPojo.setPenalty(pojo.getPenalty());
                checkRecordPojo.setEducation(pojo.getEducation());
                checkRecordPojo.setRectification(pojo.getRectification());
                checkRecordPojo.setRectAttach1(pojo.getRectAttach1());
                checkRecordPojo.setRectAttach2(pojo.getRectAttach2());
                checkRecordPojo.setRectAttach3(pojo.getRectAttach3());
                checkRecordPojo.setRectAttach4(pojo.getRectAttach4());
                checkRecordPojo.setRectVideo(pojo.getRectVideo());
                if (pojo.getVerifyPersonEmpID()!=null)
                    checkRecordPojo.setVerifyPersonEmpID(pojo.getVerifyPersonEmpID());
                checkRecordPojo.setVerifyPersonName(pojo.getVerifyPersonName());
                checkRecordPojo.setVerifyDate(pojo.getVerifyDate());
                checkRecordPojo.setRectEffect(pojo.getRectEffect());
                checkRecordPojo.setStatus(pojo.getStatus());
                checkRecordPojo.setSupervisionTaskCode(pojo.getSupervisionTaskCode());
                checkRecordPojo.setSupervisionTaskDetail2ID(pojo.getSupervisionTaskDetail2ID());
                checkRecordPojo.setRound(pojo.getRound());
                checkRecordPojo.setCheckListID(pojo.getCheckListID());
                checkRecordPojo.setCheckListName(pojo.getCheckListName());
                checkRecordPojo.setCheckRecordNo(pojo.getCheckRecordNo());
                checkRecordPojo.setBasicCompanyName(pojo.getBasicCompanyName());
                checkRecordPojo.setNote(pojo.getNote());
                //hashmap的值
                rectRecordOutDto.setRectRecordID(pojo.getRectRecordID());
                rectRecordOutDto.setSupervisorID(pojo.getRectSupervisorID());
                rectRecordOutDto.setSupervisorName(pojo.getRectSupervisorName());
                rectRecordOutDto.setRectAttach1(pojo.getRectRecordAttach1());
                rectRecordOutDto.setRectAttach2(pojo.getRectRecordAttach2());
                rectRecordOutDto.setRectAttach3(pojo.getRectRecordAttach3());
                rectRecordOutDto.setRectAttach4(pojo.getRectRecordAttach4());
                rectRecordOutDto.setRectVideo(pojo.getRectRecordVideo());
                rectRecordOutDto.setRectDescription(pojo.getRectRecordDescription());
                rectRecordOutDto.setRectFile(pojo.getRectRecordFile());
                rectRecordOutDto.setRectDate(pojo.getRectDate());
                rectRecordOutDto.setRectEffect(pojo.getRectRecordEffect());
                list.add(rectRecordOutDto);
                map.put(checkRecordPojo,list);
                System.out.println("111");
            }else {
                RectRecordOutDto rectRecordOutDto =  new RectRecordOutDto();
                List<RectRecordOutDto> list=new ArrayList<>();
                for(Map.Entry<CheckRecordRectRecordDto, List<RectRecordOutDto>> entry : map.entrySet()){
                    CheckRecordRectRecordDto checkRecordRectRecordDto= entry.getKey();
                    if (checkRecordRectRecordDto.getId()==pojo.getCheckRecordID()){
                        list = map.get(checkRecordRectRecordDto);
                        break;
                    }
                }
                //hashmap的值
                rectRecordOutDto.setRectRecordID(pojo.getRectRecordID());
                rectRecordOutDto.setSupervisorID(pojo.getRectSupervisorID());
                rectRecordOutDto.setSupervisorName(pojo.getRectSupervisorName());
                rectRecordOutDto.setRectAttach1(pojo.getRectRecordAttach1());
                rectRecordOutDto.setRectAttach2(pojo.getRectRecordAttach2());
                rectRecordOutDto.setRectAttach3(pojo.getRectRecordAttach3());
                rectRecordOutDto.setRectAttach4(pojo.getRectRecordAttach4());
                rectRecordOutDto.setRectVideo(pojo.getRectRecordVideo());
                rectRecordOutDto.setRectDescription(pojo.getRectRecordDescription());
                rectRecordOutDto.setRectFile(pojo.getRectRecordFile());
                rectRecordOutDto.setRectDate(pojo.getRectDate());
                rectRecordOutDto.setRectEffect(pojo.getRectRecordEffect());
                list.add(rectRecordOutDto);
                System.out.println("111");
            }
        }
        return returnCheckRectRecord(map, code);
    }

    //根据主题子主题显示树状
    public List<QHSEECheckRecordNumsDto> returnCurrentQhseElementList1(Map<String, QHSEECheckRecordNumsDto> map, List<Integer> code) {
        List<QHSEECheckRecordNumsDto> result = new ArrayList<>();
        Collections.sort(code);
        for (Map.Entry<String, QHSEECheckRecordNumsDto> entry : map.entrySet()) {
            String key = entry.getKey();
            if (key.length() == code.get(0))
                result.add(entry.getValue());
            else {
                QHSEECheckRecordNumsDto treeDto = map.get(key.substring(0, code.get(code.indexOf(key.length()) - 1)));
                if (null == treeDto)
                    continue;
                if (null == treeDto.getChildren()) {
                    List<QHSEECheckRecordNumsDto> tmp = new ArrayList<>();
                    tmp.add(entry.getValue());
                    treeDto.setChildren(tmp);
                } else
                    treeDto.getChildren().add(entry.getValue());
            }
        }
        return result;
    }

    public List<QHSEECheckRecordNumsDto> getCurrentQhseElementTree1(List<QHSEECheckRecordNumsDto> qhseElementsPojos) {
        Map<String, QHSEECheckRecordNumsDto> map1 = new TreeMap<>();
        List<Integer> code = new ArrayList<>();
        for (QHSEECheckRecordNumsDto pojo : qhseElementsPojos) {
            map1.put(pojo.getCode(), pojo);
            //存入长度相同的数字
            if (code.indexOf(pojo.getCode().length()) == -1)
                code.add(pojo.getCode().length());
        }
        return returnCurrentQhseElementList1(map1, code);
    }
}
